package com.coderfans.htmlparser;

import com.google.common.base.Charsets;
import com.google.common.io.Files;
import org.apache.commons.io.FileUtils;
import org.apache.log4j.net.SyslogAppender;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;

/**
 * Created by ${fanchunshuai} on 2017-7-11.
 *
 * @version: V1.0
 * @Desc: 单线程遍历文件操作
 * @Copyright (c) 2017 58到家-版权所有
 */
public class ReadHtml {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        File file = new File("E:\\spiderFile\\csdn");

        File sqlFile = new File("E:\\spiderFile\\csdnUserLink.txt");

        File [] fileList = file.listFiles();

        for (File file1 : fileList){
            String userSql = "http://my.csdn.net/"+file1.getName();
            try {
                Files.append(userSql.toString()+"\n",sqlFile, Charsets.UTF_8); //追加文件
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

        /*String [] ext = {"html"};
        for (File file1 : fileList){
            if(file1.isDirectory()){
                Iterator<File> it = FileUtils.iterateFiles(file1,ext,true);
                System.out.println("it start....");
                while (it.hasNext()){
                    System.out.println(it.next().getName());
                }
            }
        }*/

        long end = System.currentTimeMillis();

        System.out.println("end - start = "+(end - start));

    }
}
